﻿<phone:PhoneApplicationPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:viewmodels="clr-namespace:Omnia.ViewModels;assembly=Omnia.ViewModels"
    xmlns:Converters="clr-namespace:Omnia.Converters;assembly=Omnia.Converters" 
    xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions" 
    xmlns:es="clr-namespace:Microsoft.Expression.Shapes;assembly=Microsoft.Expression.Drawing" 
    x:Class="Omnia.Wallet.Views.TransactionsView"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="False">

    <phone:PhoneApplicationPage.Resources>
        <Converters:EnumTranslateConverter x:Key="EnumTranslateConverter"/>
        <Converters:ResourceKeyToPathdataConverter x:Key="ResourceKeyToPathdataConverter" />
        <Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>

    	<Style TargetType="ListBoxItem" x:Key="style_transaction_item">
    		<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    		<Setter Property="Template">
    			<Setter.Value>
    				<ControlTemplate TargetType="ListBoxItem">
    					<toolkit:ExpanderView Margin="0,6">
    						<toolkit:ExpanderView.Header>
    							<Grid Width="456" >
    								<Grid Margin="0,0,0,6">
    									<Grid.ColumnDefinitions>
    										<ColumnDefinition />
    										<ColumnDefinition Width="auto"/>
    									</Grid.ColumnDefinitions>
    									<TextBlock Text="{Binding StringFormat=\{0:MM-dd\, yyyy\}, Path=Date}" Style="{StaticResource PhoneTextTitle3Style}"/>
    									<TextBlock Text="{Binding Sum}"  Style="{StaticResource PhoneTextNormalStyle}" Grid.Column="1"/>
    								</Grid>

    								<Grid Height="1" Background="{StaticResource PhoneAccentBrush}" VerticalAlignment="Bottom" Margin="12,0"/>
    							</Grid>

    						</toolkit:ExpanderView.Header>
                            <ListBox ItemsSource="{Binding TransactionCollection}">
                                <ListBox.ItemContainerStyle>
                                    <Style TargetType="ListBoxItem">
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="ListBoxItem">
                                                    <Grid HorizontalAlignment="Stretch" Width="400">
                                                        <VisualStateManager.CustomVisualStateManager>
                                                            <ec:ExtendedVisualStateManager/>
                                                        </VisualStateManager.CustomVisualStateManager>
                                                        <Grid.ColumnDefinitions>
                                                            <ColumnDefinition Width="auto"/>
                                                            <ColumnDefinition />
                                                            <ColumnDefinition Width="auto"/>
                                                        </Grid.ColumnDefinitions>
                                                        <Grid.RowDefinitions>
                                                            <RowDefinition/>
                                                            <RowDefinition Height="auto"/>
                                                        </Grid.RowDefinitions>

                                                        <toolkit:ContextMenuService.ContextMenu>
                                                            <toolkit:ContextMenu>
                                                                <toolkit:MenuItem Header="{StaticResource IDS_LABEL_TRANS_MENU_EDIT}" Tag="{Binding Guid}" Click="GotoTransactionEditView" />
                                                                <toolkit:MenuItem Header="{StaticResource IDS_LABEL_TRANS_MENU_DELETE}" Tag="{Binding Guid}" Click="DeleteTransaction"/>
                                                            </toolkit:ContextMenu>
                                                        </toolkit:ContextMenuService.ContextMenu>
                                                        <Path Data="{Binding Category.IconResourceKey, Converter={StaticResource ResourceKeyToPathdataConverter}}" 
                                                              Stretch="Uniform" 
                                                              Fill="{StaticResource PhoneForegroundBrush}" 
                                                              Width="20" Height="20" Margin="12" 
                                                              RenderTransformOrigin="0.5,0.5">
                                                            <Path.RenderTransform>
                                                                <TransformGroup>
                                                                    <RotateTransform Angle="0" />
                                                                    <ScaleTransform ScaleX="1" ScaleY="1" />
                                                                </TransformGroup>
                                                            </Path.RenderTransform>
                                                        </Path>
                                                        <TextBlock Text="{Binding Category.Name}" 
                                                                   Style="{StaticResource PhoneTextNormalStyle}" 
                                                                   Grid.Column="1" VerticalAlignment="Center" />
                                                        <TextBlock Text="{Binding Amount, StringFormat=\{0:c\}}" 
                                                                   Style="{StaticResource PhoneTextLargeStyle}" 
                                                                   Grid.Column="2" VerticalAlignment="Center" 
                                                                   Foreground="{StaticResource PhoneAccentBrush}"/>

                                                        <Grid x:Name="grid" Grid.Row="1" Margin="12,0" 
                                                              Grid.ColumnSpan="3" 
                                                              Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}">
                                                            <Grid.RowDefinitions>
                                                                <RowDefinition Height="auto"/>
                                                                <RowDefinition Height="auto"/>
                                                            </Grid.RowDefinitions>
                                                            <es:RegularPolygon Fill="{StaticResource PhoneSubtleBrush}" HorizontalAlignment="Right" 
                                                                               InnerRadius="1" 
                                                                               PointCount="3" 
                                                                               Stretch="Fill" 
                                                                               UseLayoutRounding="False" 
                                                                               Width="20" Height="16" Margin="0,0,20,0" 
                                                                               StrokeThickness="0"/>
                                                            <StackPanel Grid.Row="1" Background="{StaticResource PhoneSubtleBrush}">
                                                                <Grid>
                                                                    <Grid.ColumnDefinitions>
                                                                        <ColumnDefinition/>
                                                                        <ColumnDefinition Width="auto"/>
                                                                    </Grid.ColumnDefinitions>
                                                                    <TextBlock Text="{Binding Paymentway, Converter={StaticResource EnumTranslateConverter}}" 
                                                                               Style="{StaticResource PhoneTextNormalStyle}" 
                                                                               Foreground="{StaticResource PhoneChromeBrush}" />
                                                                    <TextBlock Text="{Binding Time, StringFormat=HH:mm}" 
                                                                               Grid.Column="1" 
                                                                               Style="{StaticResource PhoneTextNormalStyle}" 
                                                                               Foreground="{StaticResource PhoneChromeBrush}" />
                                                                </Grid>
                                                                <TextBlock Style="{StaticResource PhoneTextNormalStyle}" 
                                                                           TextWrapping="Wrap" 
                                                                           Foreground="{StaticResource PhoneChromeBrush}">
                                                                    <Run Text="{StaticResource IDS_LABEL_TRANS_REMARK}"/>
                                                                    <Run Text="： "/>
                                                                    <Run Text="{Binding Remark}"/>
                                                                </TextBlock>
                                                                <TextBlock Style="{StaticResource PhoneTextNormalStyle}" 
                                                                           TextWrapping="Wrap" 
                                                                           Foreground="{StaticResource PhoneChromeBrush}">
                                                                    <Run Text="{StaticResource IDS_LABEL_TRANS_LINK}"/>
                                                                    <Run Text="： "/>
                                                                    <Run Text="{Binding Case.Title}"/>
                                                                </TextBlock>
                                                            </StackPanel>
                                                        </Grid>
                                                    </Grid>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </ListBox.ItemContainerStyle>
                            </ListBox>
    						
    					</toolkit:ExpanderView>
    				</ControlTemplate>
    			</Setter.Value>
    		</Setter>
    	</Style>
    </phone:PhoneApplicationPage.Resources>
    
    <Grid x:Name="LayoutRoot">
        <Grid.Background>
            <ImageBrush ImageSource="{Binding BackgroundImageSource, Mode=OneWay}" Stretch="{Binding GlobalSettings.BackgroundImageStretch}"/>
        </Grid.Background>
        <Grid.RowDefinitions>
        	<RowDefinition />
        	<RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <Grid.DataContext>
            <viewmodels:TransactionViewModel/>
        </Grid.DataContext>
        <controls:Pivot Title="{StaticResource IDS_PAGE_TITLE}">
            <!--Pivot item one-->
            <controls:PivotItem Header="{StaticResource IDS_ITEM_HEADER_INCOME}" HorizontalContentAlignment="Stretch">
                <ListBox ItemsSource="{Binding IncomeCollection}" ItemContainerStyle="{StaticResource style_transaction_item}"/>
            </controls:PivotItem>

            <!--Pivot item two-->
            <controls:PivotItem Header="{StaticResource IDS_ITEM_HEADER_EXPENSE}">
                <ListBox ItemsSource="{Binding ExpenseCollection}" ItemContainerStyle="{StaticResource style_transaction_item}"/>
            </controls:PivotItem>
        </controls:Pivot>
        
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
            	<ColumnDefinition Width="auto"/>
            	<ColumnDefinition />
            </Grid.ColumnDefinitions>

            <Grid>
                <Grid.ColumnDefinitions>
                	<ColumnDefinition Width="auto"/>
                	<ColumnDefinition Width="auto"/>
                </Grid.ColumnDefinitions>
                <Button VerticalAlignment="Center" Margin="12" Command="{Binding IncreaseMonthCommand}">
                    <Button.Style>
                        <Style TargetType="Button">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="Button">
                                        <Grid>
                                            <Grid Background="White" Opacity="0"/>
                                            <Path Data="F1 M753.64398,-13.0589 L753.73602,-12.9639 L753.55701,-12.7816 L732.13702,8.6364098 L732.13702,29.711901 L756.44501,5.4085102 L764.09399,-2.24384 L764.27502,-2.4235201 L771.83398,5.1286001 L796.13702,29.437201 L796.13702,8.3616304 L774.72198,-13.0589 L764.18103,-23.596701 L753.64398,-13.0589 z" 
                                                  Stretch="Uniform" 
                                                  Fill="{StaticResource PhoneForegroundBrush}" 
                                                  Width="30" Height="30" 
                                                  Margin="0,0,0,0" 
                                                  RenderTransformOrigin="0.5,0.5">
                                                <Path.RenderTransform>
                                                    <TransformGroup>
                                                    	<RotateTransform Angle="0" />
                                                    	<ScaleTransform ScaleX="1" ScaleY="1" />
                                                    </TransformGroup>
                                                </Path.RenderTransform>
                                            </Path>
                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </Button.Style>
                </Button>

                <Button VerticalAlignment="Center" Margin="0" Grid.Column="1" Command="{Binding DecreaseMonthCommand}">
                    <Button.Style>
                        <Style TargetType="Button">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="Button">
                                        <Grid>
                                            <Grid Background="White" Opacity="0"/>
                                            <Path Data="F1M181.297,177.841L181.205,177.746 181.385,177.563 202.804,156.146 202.804,135.07 178.497,159.373 170.847,167.026 170.666,167.205 163.107,159.653 138.804,135.345 138.804,156.42 160.219,177.841 170.76,188.379 181.297,177.841z" 
                                                  Stretch="Uniform" 
                                                  Fill="{StaticResource PhoneForegroundBrush}" 
                                                  Width="30" Height="30" 
                                                  Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5">
                                                <Path.RenderTransform>
                                                    <TransformGroup>
                                                    	<RotateTransform Angle="0" />
                                                    	<ScaleTransform ScaleX="1" ScaleY="1" />
                                                    </TransformGroup>
                                                </Path.RenderTransform>
                                            </Path>
                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </Button.Style>
                </Button>
            </Grid>
            
            <toolkit:DatePicker Grid.Column="1" Value="{Binding SelectedDate, Mode=TwoWay}" ValueStringFormat="{}{0:D}" />
        </Grid>
    </Grid>
    
</phone:PhoneApplicationPage>